package com.wuneng.ircontrol.module.act;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.wuneng.commonlibrary.util.SharedPreferencesHelper;

import java.io.File;

import com.wuneng.ircontrol.R;
import com.wuneng.ircontrol.common.util.Constants;
import com.wuneng.ircontrol.myUtil.common.Util;


/**
 * 闪屏页面
 */
public class SplashActivity extends Activity implements Animation.AnimationListener {
    private Animation alphaAnimation = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SetPath();
        View view = LayoutInflater.from(this).inflate(R.layout.act_splash, null);
        setContentView(view);
        Constants.SERVER.SERVER_IP = SharedPreferencesHelper.GetValue(SplashActivity.this, Constants.SharedPreferenceTag.SERVER_IP, Constants.SERVER.SERVER_IP);
        alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.welcome_alpha);
        alphaAnimation.setFillEnabled(true); // 启动Fill保持
        alphaAnimation.setFillAfter(true); // 设置动画的最后一帧是保持在View上面
        view.setAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(this); // 为动画设置监听
    }

    /**z
     * 设置照片,日志等存储位置
     */
    public void SetPath() {
        String filepath;

        if (Build.VERSION.SDK_INT < 18)// 4.4以上好像不能在SD卡创建文件夹
        {
            filepath = Util.GetStoragePath(SplashActivity.this, true);// 先考虑外部SD卡
        } else
            filepath = Util.GetStoragePath(SplashActivity.this, false);// 使用内部存储卡

        if (filepath == "") {
            filepath = Util.GetStoragePath(SplashActivity.this, false);// 再考虑是否使用内部存储卡
            if (filepath == "")
                filepath = SplashActivity.this.getFilesDir() + "";// 如果使用系统内存，则不能使用系统自带相机。。
        }

        filepath = filepath + "/" + getString(R.string.app_name);


        File file1 = new File(filepath + "/Log/");
        if (!file1.exists()) {
            file1.mkdirs();
        }


        Constants.FILE_PATH.LOG_PATH = filepath + "/Log/";
    }


    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        startActivity(new Intent(SplashActivity.this, HomeActivity.class));
        SplashActivity.this.finish();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
    }


}
